package com.banch.cloud.hystrix.controller;

import com.banch.cloud.hystrix.service.impl.PaymentServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * payment controller
 *
 * @author banch
 * @version 1.0
 * @date 2020/7/9
 */
@Slf4j
@RequestMapping(value = "/payment")
@Controller
public class PaymentController {

    /**
     * paymentService
     */
    @Resource
    private PaymentServiceImpl paymentService;

    /**
     * serverPort
     */
    @Value(value = "${server.port}")
    private String serverPort;


    /**
     * description
     *
     * @author banch
     * @date 2020/7/10
     * @param 
     * @return 
     * @throw 
     **/
    @ResponseBody
    @GetMapping(value = "/hystrix/ok/{id}")
    public String paymentOK(@PathVariable(value = "id") Integer id) {
        log.info("payment ok,id:{}", id);
        return paymentService.paymentInfoOK(id);
    }


    /**
     * description
     *
     * @author banch
     * @date 2020/7/10
     * @param 
     * @return 
     * @throw 
     **/
    @ResponseBody
    @GetMapping(value = "/hystrix/timeout/{id}")
    public String paymentTimeout(@PathVariable(value = "id") Integer id) {
        log.info("payment timeout,id:{}", id);
        return paymentService.paymentInfoTimeout(id);
    }



    //===服务熔断
    @ResponseBody
    @GetMapping("/circuit/{id}")
    public String paymentCircuitBreaker(@PathVariable("id") Integer id){
        String result = paymentService.paymentCircuitBreaker(id);
        log.info("*******result:"+result);
        return result;
    }


}